<template>
  <div class="search">
    <div class="content">
      <div style="width: 234px; height: 70px"></div>
      <div class="search-info">
        <div class="search-msg">
          <div class="search-input-box">
            <img
              src="http://localhost:3000/sousuo.png"
              class="search-btn-img"
            />
            <input
              type="text"
              v-model="productName"
              placeholder="请输入商品名称"
              class="search-input"
            />
          </div>
          <input
            @click="goSearch"
            type="submit"
            class="search-btn"
            value="搜索"
            style="letter-spacing: 2px"
          />
        </div>
        <div class="cart-btn" @click="$router.push('/shopCart')">
          <img
            src="http://localhost:3000/cart.png"
            class="search-car-btn-img"
          />
          购物车
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts" name="search">
import {ref} from 'vue'
import { useRoute,useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
// 获取路由器对象
let $route = useRoute()
let $router = useRouter()
// 搜索关键字
let productName = ref<string>('')

// 点击搜索的回调
const goSearch = () => {
  if(productName.value == ''){
    ElMessage.error("商品名称不能为空")
    return
  }
  $router.push({path:'/goodsList',query:{productName:productName.value}})
}
</script>

<style lang="scss" scoped>
.search {
  background: #fff;
  width: 100%;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.05);
  border-bottom: 2px solid #4caf50;
  .content {
    height: 94px;
    width: 1200px;
    margin: auto;
    display: flex;
    justify-content: space-between;
    -webkit-justify-content: space-between;
    padding-top: 13px;
    box-sizing: border-box;
    .search-info {
      display: flex;
      .search-msg {
        position: relative;
        height: 40px;
        .search-input-box {
          display: inline-block;
          border: 2px solid #4caf50;
          width: 430px;
          position: relative;
          .search-btn-img {
            height: 20px;
            position: absolute;
            right: 59px;
            top: 13px;
            z-index: 99;
            width: 20px;
            vertical-align: middle;
            margin-right: 12px;
          }
          .search-input {
            display: inline-block;
            width: 430px;
            border: 0;
            height: 46px;
            padding: 0 10px;
            font-size: 16px;
          }
        }
        .search-btn {
          border: 0;
          background: #4caf50;
          color: #fff;
          height: 47px;
          width: 100px;
          position: absolute;
          top: 0;
          right: 0;
          letter-spacing: 2px;
          font-size: 14px;
          cursor: pointer;
          padding-left: 20px;
          transition: all 0.2s;
          -webkit-transition: all 0.2s;
        }
      }
      .cart-btn {
        display: flex;
        align-items: center;
        margin-left: 20px;
        padding: 0 20px;
        background-color: #fff;
        border: 1px solid #4caf50;
        height: 46px;
        line-height: 46px;
        color: #4caf50;
        font-size: 14px;
        cursor: pointer;
        transition: all 0.2s;
        -webkit-transition: all 0.2s;
        position: relative;
        .search-car-btn-img{
          width: 20px;
          height: 20px;
        }
      }
    }
  }
}
</style>
